Skip to content

fix(durable): keep timers across recovery and skip idle ticks - #236

Merged
reka18 merged 5 commits into
mainfrom
fix/durable-timers
Nov 18, 2026
Merged

reka18 merged 5 commits into
mainfrom
fix/durable-timers

Conversation

@reka18

@reka18 reka18 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What this change does

Timers survive recovery, and idle ticks stop growing the journal.

  • Start arms the initial state's timers and carries them in the baseline. An instance started before this change keeps its initial timer unarmed. Start arms them even when the initial entry failed, as it already starts that state's services and actors.
  • Recover re-arms checkpointed timers before the tail replays, so a tail tick can fire them. A held replay clock keeps that arming from consuming a recorded reading. StateAt re-arms the baseline's timers the same way.
  • A tick that fires nothing records nothing and doesn't touch the Store. It drops only its own clock reads, and keeps the ones a pending parent Fire from Start's or Recover's actors took, which the next step records. An idle tick takes no step number and doesn't count toward WithCheckpointEvery. A stale owner finds out on its next real step, not on the idle tick.
  • Replay reads an older journal's idle tick Record as nothing fired and skips its readings. A recorded reading no replayed step consumed is no longer handed to the first timer armed after Recover.
  • The journal format is now 3. Recover and StateAt fail when a tick of format 3 or later fires a different number of timers on replay than its Record says, rather than replaying the steps after it in another state. An older Record isn't checked (see below).
  • The Tick godoc says a timer whose transition fails is reported only in its FireResult.Err.

Please check these:

  • Behavior change: an instance starting in a timed state now fires a timer it didn't before, because Start never armed one, even live.
  • For your ruling (durable: defects found in the platform-redesign review #214 question 8): the proposal was to return a failed timer transition's error from Tick. This PR leaves it in FireResult.Err and documents that. It's a suggestion: say if you'd rather Tick return it.
  • Older journals after an older recovery: that version's Recover re-armed a checkpoint's timers after the tail. So a journal it continued can record a timer the tail had fired or canceled firing again. A canceled one it revived usually fired into a refusal, and replays to the same state. If the state it was in then takes the timer's event, or the timer fired twice, replay diverges from that run with no error, as that version's own replay did. Nothing in a format-2 journal tells these apart, so none fails Recover. Replay also skips any reading such a tick leaves, so the next Record reads its own.
  • Downgrades: an older durable re-arms a baseline's or checkpoint's timers only after the tail, so it silently misses one a tail tick fired. The CHANGELOG's "don't downgrade" note now names it.
  • A journal written before tickDriversFormat can put a settle's clock read in the next Record, so replay can arm that timer at the wrong instant. That's durable: an older journal's misplaced settle clock read can arm a replayed timer at the wrong instant #262, and its four tests are skipped with that number.

Known and left open: checkpoints still grow with trace history, and the size metric #214 question 9 proposes has no home yet. DeliverToActor passes no effects to the scheduler, so a state entered by delivery never arms its timer.

Why

Start never armed the initial state's timers, even live. A checkpointed timer that a tail tick fired was missed on replay. Every idle tick appended a Record.

Relates to: #214

Evidence

On GOTOOLCHAIN=go1.27.4:

Command Result
mage check (lint, race tests, govulncheck) Pass in all 13 modules
go test -race ./... in durable Pass

The older-journal tests build their journals at format 1, older than tickDriversFormat, the kind of version that still recorded idle ticks. New tests pin the idle tick keeping a pending parent Fire's read, the format-3 tick-count check, and an older journal's revived timer recovering; each fails with its fix reverted.

Checklist

  • Commits are signed off (git commit -s) per the DCO
  • Conventional commit messages (type: subject)
  • mage check passes locally (lint + race tests + govulncheck)
  • Tests added/updated for the change
  • Public API changes documented (godoc) and, if applicable, noted for the changelog

@reka18 reka18 added not-ready On every new PR until all review dimensions are confirmed wait:correctness ACR pending: correctness wait:regression-safety ACR pending: regression-safety wait:concurrency-discipline ACR pending: concurrency-discipline wait:replay-determinism ACR pending: replay-determinism wait:api-compatibility ACR pending: api-compatibility wait:missed-context ACR pending: missed-context wait:human-readability ACR pending: human-readability labels Nov 5, 2026
@reka18
reka18 force-pushed the fix/durable-timers branch from 29736b8 to c6e5aa6 Compare November 5, 2026 16:38
@reka18
reka18 force-pushed the fix/durable-timers branch from c6e5aa6 to f4697dc Compare November 5, 2026 16:40
@reka18
reka18 force-pushed the fix/durable-timers branch from f4697dc to e653227 Compare November 5, 2026 16:53
@reka18
reka18 force-pushed the fix/durable-timers branch from e653227 to 8db4d1e Compare November 5, 2026 17:09
@reka18
reka18 force-pushed the fix/durable-timers branch from 8db4d1e to cb8ca81 Compare November 5, 2026 17:14
@reka18
reka18 force-pushed the fix/durable-timers branch from cb8ca81 to 6e0908c Compare November 5, 2026 17:22
@reka18
reka18 force-pushed the fix/durable-timers branch from 6e0908c to bd0e889 Compare November 5, 2026 17:34
@reka18
reka18 added this pull request to stack #238 November 5, 2026 17:34
@reka18
reka18 force-pushed the fix/durable-timers branch from bd0e889 to 189e001 Compare November 5, 2026 17:42
@reka18
reka18 force-pushed the fix/durable-timers branch from 189e001 to c02481a Compare November 5, 2026 18:04
@reka18
reka18 force-pushed the fix/durable-timers branch from c02481a to a03ba52 Compare November 5, 2026 18:20
@reka18
reka18 added this pull request to stack #239 November 5, 2026 20:26
@reka18
reka18 force-pushed the fix/durable-timers branch from 1738b1a to 372a253 Compare November 5, 2026 20:52
@reka18
reka18 force-pushed the fix/durable-timers branch from 372a253 to b33de98 Compare November 5, 2026 21:02
@reka18 reka18 added ready All ACR dimensions confirmed - clear to merge confirmed:correctness ACR clean: correctness confirmed:regression-safety ACR clean: regression-safety confirmed:concurrency-discipline ACR clean: concurrency-discipline confirmed:replay-determinism ACR clean: replay-determinism and removed not-ready On every new PR until all review dimensions are confirmed wait:correctness ACR pending: correctness wait:regression-safety ACR pending: regression-safety wait:concurrency-discipline ACR pending: concurrency-discipline wait:replay-determinism ACR pending: replay-determinism wait:api-compatibility ACR pending: api-compatibility labels Nov 5, 2026
@reka18

reka18 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Review results. One reviewer per dimension, each reading the others' findings. All seven dimensions have zero blockers on the latest round.

Fixed along the way: the Handle's timer table now follows the scheduler, and each chained timer takes the deadline the scheduler armed. Replay aligns on each Record, so older journals with a misplaced settle read recover, including across a restart. Every fix has a test confirmed to fail without it.

Fuzzing journals this PR writes found no mismatch in about 80,000 operations per run.

Known limits, in the changelog: two kinds of older journal can't be repaired and can fail Recover. A failed timer transition is reported only in its FireResult (#214 question 8).

Start now arms the initial state's timers and carries them in the baseline.
Recovery re-arms checkpointed timers before the tail replays, so one fired in
the tail isn't missed, and StateAt re-arms the baseline's. A tick that fires
nothing records nothing, so a timer loop no longer grows the journal; replay
reads an older journal's idle tick Record as nothing fired, and a reading no
replayed step consumed no longer reaches the live clock.

An older journal's settle read placed in the next Record is left to #262.

Relates to #214.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
…tick

An idle Tick dropped every reading in the clock buffer, including the one a
parent Fire that Start's or Recover's actors drove took arming its timer. The
next step journals that Fire, so replay armed its timer at a later reading. An
idle Tick now drops only its own reads.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
Recover and StateAt now fail when a replayed tick fires a different number of
timers than its Record's TickSteps, rather than replaying the following steps in
another state. An older version's recovery that missed a checkpointed timer
fired in its tail, then fired it again live, leaves such a journal.

Docs now say which clock readings are journaled, that recovery re-arms timers
before the tail, that Start arms timers on a failed entry, that an idle tick
doesn't count toward WithCheckpointEvery, and what an older durable does with a
baseline that carries timers.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
…ecords

An older version's recovery re-armed a checkpoint's timers after the tail, so a
journal it continued can record a tick firing a timer the tail had canceled,
which replay keeps canceled. Journal format is now 3, and replay checks a
tick's fired count only for a Record of format 3 or later, so such a journal
recovers to the state that version reached.

Docs say which readings Start and an idle Tick leave unjournaled, that Recover
fails on a format-3 tick count mismatch, and what an older durable's Recover
and StateAt do with a baseline's timers.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
An older tick that records a timer replay keeps canceled reads fewer readings
than its Record holds, and the rest went to the next Record, so a later Recover
replayed it at the wrong instants. Replay now skips past each Record's readings
once it has replayed it, in Recover and StateAt.

Docs say the tick-count check applies from journal format 3, in replayRecord,
Recover, StateAt and Record's godoc.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
@reka18

reka18 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Review results. One AI reviewer per dimension, each in a clean context, plus a probe reviewer that tried to break the change with tests. Every dimension has zero blockers on its latest round, at cc13ba8.

Fixed along the way:

  • An idle Tick dropped the clock read a pending parent Fire from Start's or Recover's actors had taken, so the next step recorded that Fire without it and its timer replayed at the wrong deadline. An idle tick now drops only its own reads (377c20d).
  • The journal format is now 3. Replay fails when a format-3 tick fires a different number of timers than it recorded. An older Record isn't checked: an older version's recovery re-armed a checkpoint's timers after the tail, so it could revive a timer the tail canceled, and that tick fired into a refusal. Checking it would refuse a journal main writes and replays correctly (ae2a95e).
  • An older tick like that reads fewer readings than its Record holds. The rest went to the next Record, so a later Recover replayed it at the wrong instants. Replay now skips past each Record's readings (cc13ba8).
  • Docs now say which readings Start and an idle tick leave unjournaled, that recovery re-arms timers before the tail, that Start arms timers on a failed entry, that an idle tick doesn't count toward WithCheckpointEvery, and what an older durable does with a baseline that carries timers.

Each fix has a test that fails with the fix reverted. mage check passes in all 13 modules.

Known and left open:

  • A timer an older version's recovery fired twice, or revived into a state that takes its event, still replays differently from that run with no error, as that version's own replay did. The CHANGELOG says so.
  • durable: an older journal's misplaced settle clock read can arm a replayed timer at the wrong instant #262: an older journal's settle read in the next Record. Its four tests are skipped.
  • transport's time-travel view passes no options, so StateAt there fails for a machine whose timer events need a custom codec. The CHANGELOG says so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

confirmed:api-compatibility ACR clean: api-compatibility confirmed:concurrency-discipline ACR clean: concurrency-discipline confirmed:correctness ACR clean: correctness confirmed:human-readability ACR clean: human-readability confirmed:missed-context ACR clean: missed-context confirmed:probes ACR: the probes lens's latest round found no blocker confirmed:regression-safety ACR clean: regression-safety confirmed:replay-determinism ACR clean: replay-determinism ready All ACR dimensions confirmed - clear to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants